package com.zbl.zblproject.erp.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.zbl.zblproject.core.entity.*;
import com.zbl.zblproject.core.mapper.AdminUserMapper;
import com.zbl.zblproject.core.mapper.OrderItemMapper;
import com.zbl.zblproject.core.mapper.SupplierMapper;
import com.zbl.zblproject.core.utils.ResultUtil;
import com.zbl.zblproject.erp.entity.*;
import com.zbl.zblproject.erp.mapper.BalanceMapper;
import com.zbl.zblproject.erp.mapper.ErpGoodMapper;
import com.zbl.zblproject.erp.mapper.ErpOrderMapper;
import com.zbl.zblproject.erp.service.ErpOrderService;
import com.zbl.zblproject.erp.utils.ErpOrderFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Min;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/10/10
 * 出入库操作接口
 */
@RestController
@Api(value = "出入库操作接口", tags = {"出入库操作接口"})
@RequestMapping("/erp-order")
public class ErpOrderController {


    /**
     * 入库单/欠货
     */
    public static int MODE_IN = 0;

    /**
     * 出库单/缺货
     */
    public static int MODE_OUT = 1;

    /**
     * 退货单
     */
    public static int MODE_RETURN = 2;


    private static Logger logger = LoggerFactory.getLogger(ErpOrderController.class);


    @Value("${img-path}")
    private String imgPath;

    @Autowired
    private ErpOrderService erpOrderService;

    @Autowired
    private AdminUserMapper userMapper;

    @Autowired
    private OrderItemMapper orderItemMapper;

    @Autowired
    private ErpOrderMapper erpOrderMapper;

    @Autowired
    private SupplierMapper supplierMapper;


    @PostMapping("/remote-out")
    @ApiOperation("远程出库单")
    public Result remoteOutOrder(@ApiParam("用户姓名") @RequestParam("userName") String userName,
                                 @ApiParam("过滤订单号") @RequestParam("notin") String json) {
        try {
            AdminUser user = userMapper.selectOneByName(userName);
            if (user == null) {
                return ResultUtil.error("远程服务器不存在该用户!");
            }
            List<String> notIn = JSONArray.parseArray(json, String.class);
            List<Order> orders = erpOrderService.getRemoteOutOrder(notIn, user);
            return ResultUtil.success("成功!", JSONArray.toJSONString(orders));
        } catch (RuntimeException e) {
            return ResultUtil.error(e.getMessage());
        }
    }

    @GetMapping("/ended-erp/{orderSn}")
    @ApiOperation("删除对应ERP订单")
    public Result endedErpOrder(@ApiParam("订单号") @PathVariable String orderSn) {
        if (erpOrderService.deleteErpOrder(orderSn)) {
            return ResultUtil.success("订单删除成功!");
        }
        return ResultUtil.error("订单删除失败!");
    }

    @GetMapping("/ended-owe/{orderSn}")
    @ApiOperation("终结欠货订单")
    public Result endedOweOrder(@ApiParam("订单号") @PathVariable String orderSn,
                                @ApiParam("用户ID") @RequestParam("userId") int userId) {
        AdminUser user = getUserById(userId);
        if (erpOrderService.endedOwe(orderSn, user)) {
            return ResultUtil.success("终结成功!");
        }
        return ResultUtil.error("终结失败!");
    }

    @GetMapping("/show-freight/{orderSn}")
    @ApiOperation("显示货运单图片")
    public void showImg(@ApiParam("订单的订单号") @PathVariable String orderSn,
                        HttpServletResponse response) {
        ErpOrder log = erpOrderMapper.selectErpOrderByOrderSn(orderSn);
        if (log != null && log.getFreightPath() != null) {
            File img = new File(log.getFreightPath());
            if (img.exists()) {
                String ext = FilenameUtils.getExtension(log.getFreightPath());
                response.setContentType("image/jpeg");
                response.addHeader("Content-Disposition",
                        "attachment;fileName=" + log.getOrderInfo() + "." + ext);// 设置文件名
                try (OutputStream stream = response.getOutputStream()) {
                    stream.write(FileUtils.readFileToByteArray(img));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    @PostMapping("/submit-freight/{orderSn}")
    @ApiOperation("提交货运单")
    public Result submitCertificate(@ApiParam("订单的单号") @PathVariable String orderSn,
                                    MultipartFile multipartFile) {
        if (multipartFile == null || multipartFile.isEmpty()) {
            return ResultUtil.error("没有上传任何文件!");
        }
        ErpOrder log = erpOrderMapper.selectErpOrderByOrderSn(orderSn);
        if (log == null) {
            return ResultUtil.error("没有这个收付款记录!");
        }
        File imgDir = new File(imgPath);
        if (imgDir.exists()) {
            if (imgDir.isFile()) {
                return ResultUtil.error("保存图片的路径为文件,请通知管理员!");
            }
        } else {
            if (!imgDir.mkdirs()) {
                return ResultUtil.error("创建保存图片文件夹失败,请联系管理员!");
            }
        }
        String ext = FilenameUtils.getExtension(multipartFile.getOriginalFilename());
        if (ext == null) {
            return ResultUtil.error("只支持jpg或png格式的图片!");
        }
        if (!ext.equals("jpg") && !ext.equals("png")) {
            return ResultUtil.error("只支持jpg或png格式的图片!");
        }
        String name = UUID.randomUUID() + "." + ext;
        File targetFile = new File(imgDir, name);
        try {
            multipartFile.transferTo(targetFile);
        } catch (IOException e) {
            return ResultUtil.error("保存失败!");
        }
        if (log.getFreightPath() != null) {
            FileUtils.deleteQuietly(new File(log.getFreightPath()));
        }
        log.setFreightPath(targetFile.toPath().toString());
        if (erpOrderMapper.updateById(log) == 1) {
            return ResultUtil.success("上传货运单成功!");
        } else {
            return ResultUtil.error("上传货运单失败!");
        }
    }


    @PostMapping("/update-context/{orderSn}")
    @ApiOperation("更新订单备注")
    public Result updateOrderContext(@ApiParam("订单号") @PathVariable String orderSn,
                                     @ApiParam("备注信息") @RequestParam("context") String context) {
        if (erpOrderService.updateErpOrderByContext(orderSn, context)) {
            return ResultUtil.success("更新成功!");
        }
        return ResultUtil.error("更新失败!");
    }

    @GetMapping("/get-context/{orderSn}")
    @ApiOperation("获取订单备注")
    public Result getOrderContext(@ApiParam("订单号") @PathVariable String orderSn) {
        ErpOrder order = erpOrderService.getErpOrder(orderSn);
        if (order == null) {
            return ResultUtil.error("没有该订单号.");
        }
        return ResultUtil.success("成功.", order.getContext());
    }

    @GetMapping("/rollback/{orderInfo}")
    @ApiOperation("订单状态回滚")
    public Result rollback(@ApiParam("订单号") @PathVariable String orderInfo) {
        try {
            if (erpOrderService.rollbackOrder(orderInfo)) {
                return ResultUtil.success("回滚成功!");
            } else {
                return ResultUtil.error("回滚失败!");
            }
        } catch (Exception e) {
            return ResultUtil.error(e.getMessage());
        }
    }

    @GetMapping("/pass/{orderInfo}")
    @ApiOperation("订单状态通过")
    public Result pass(@ApiParam("订单号") @PathVariable String orderInfo,
                       @ApiParam("客户ID") @RequestParam("userId") Integer userId) {
        try {
            synchronized (ErpOrderController.class) {
                ErpOrder order = erpOrderService.passOrder(orderInfo, userId);
                return ResultUtil.success("成功!", order);
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
            return ResultUtil.error(e.getMessage());
        }
    }

    @PostMapping("/addin-order/{orderNo}")
    @ApiOperation("添加用户入库单并直接入库")
    public Result addInOrderByUserOrder(@ApiParam("订单号") @PathVariable String orderNo,
                                        @ApiParam("用户ID") @RequestParam("userId") Integer userId,
                                        @ApiParam("订单商品") @RequestParam("items") String json) {
        return ResultUtil.error("该接口已经弃用,建议添加一个待审核的入库单");
    }

    @PostMapping("/addin/{orderNo}/{status}")
    @ApiOperation("添加入库单附带状态")
    public Result addInOrderAndStatus(@ApiParam("订单号") @PathVariable String orderNo,
                                      @ApiParam("用户ID") @RequestParam("userId") Integer userId,
                                      @ApiParam("工厂名称") @RequestParam("name") String name,
                                      @ApiParam("订单状态") @PathVariable Integer status,
                                      @ApiParam("订单商品") @RequestParam("items") String json,
                                      @ApiParam("订单商品") @RequestParam("context") String context) {
        return addOrderAndStatus(orderNo, userId, status, json, MODE_IN, 0, "", name, context,new BigDecimal("0"));
    }

    @PostMapping("/addreturn/{orderNo}/{status}")
    @ApiOperation("添加退货库单附带状态")
    public Result addReturnOrder(@ApiParam("订单号") @PathVariable String orderNo,
                                 @ApiParam("用户ID") @RequestParam("userId") Integer userId,
                                 @ApiParam("工厂名称") @RequestParam("name") String name,
                                 @ApiParam("订单状态") @PathVariable Integer status,
                                 @ApiParam("订单商品") @RequestParam("items") String json) {
        return addOrderAndStatus("THD" + Instant.now().toEpochMilli(), userId, status, json, MODE_RETURN, 0, orderNo, name, "",new BigDecimal("0"));
    }


    @PostMapping("/addout/{orderNo}/{status}")
    @ApiOperation("添加出库单附带状态")
    public Result addOutOrderAndStatus(@ApiParam("订单号") @PathVariable String orderNo,
                                       @ApiParam("店家ID") @RequestParam("storeId") Integer storeId,
                                       @ApiParam("原始订单号") @RequestParam("originOrder") String originOrder,
                                       @ApiParam("客户ID") @RequestParam("userId") Integer userId,
                                       @ApiParam("订单状态") @PathVariable Integer status,
                                       @ApiParam("订单备注") @RequestParam("context") String context,
                                       @ApiParam("订单商品") @RequestParam("items") String json,
                                       @ApiParam("订单商品") @RequestParam("logisticsCostRatio") BigDecimal logisticsCostRatio) {

        return addOrderAndStatus(orderNo, userId, status, json, MODE_OUT, storeId, originOrder, null, context, logisticsCostRatio);

    }

    @GetMapping("/rk-back/{orderSn}")
    @ApiOperation("入库单从已完成回滚到草稿")
    public Result intoWarehouseOrderBack(@ApiParam("订单号") @PathVariable String orderSn) {
        try {
            if (erpOrderService.rkBack(orderSn)) {
                return ResultUtil.success("订单号回滚成功");
            }
            return ResultUtil.error("订单号回滚失败");
        } catch (RuntimeException e) {
            return ResultUtil.error(e.getMessage());
        }
    }


    private Result addOrderAndStatus(String orderNo, Integer userId, Integer status, String json, int mode,
                                     Integer storeId, String originOrderSn, String searchName, String context, BigDecimal logisticsCostRatio) {
        try {
            AdminUser user = getUserById(userId);

            ErpOrder order = ErpOrderFactory.createOrder(orderNo,
                    user.getUserName(), mode);
            order.setStoreId(storeId);
            if (!Strings.isNullOrEmpty(searchName)) {
                order.setSearchName(searchName);
            } else if (storeId != 0) {
                AdminUser store = getUserById(storeId);
                order.setSearchName(store.getUserName());
            }
            order.setContext(context);
            order.setOriginOrderSn(originOrderSn);
            order.setLogisticsCostRatio(logisticsCostRatio);
            List<ErpOrderItem> erpOrderItems = parseErpOrderItems(json);
            if (null != originOrderSn && !"".equals(originOrderSn)) {
                for (ErpOrderItem erpOrderItem : erpOrderItems) {
                    if (erpOrderItem.getOrderItemId() == 0) {
                        OrderItem orderItem = orderItemMapper.selectBySnAndGoodsId(originOrderSn, erpOrderItem.getGoodsId());
                        erpOrderItem.setOrderItemId(orderItem.getId());
                    }
                }
            }
            if (order.getMode() == MODE_IN) {
                ErpOrderItem item = erpOrderItems.get(0);
                if (item.getOrderItemId() != 0) {
                    order.setOriginOrderSn(orderItemMapper.selectOrderSn(item.getOrderItemId()));
                }
                if (status != ErpOrderStatus.draft.getStatus()
                        && status != ErpOrderStatus.submit.getStatus()) {
                    return ResultUtil.error("失败", "状态只能是草稿或提交!");
                }
            } else if (order.getMode() == MODE_OUT) {
                if (status != ErpOrderStatus.draft.getStatus()
                        && status != ErpOrderStatus.submit.getStatus() &&
                        status != ErpOrderStatus.finance.getStatus()) {
                    return ResultUtil.error("失败", "状态只能是草稿或提交!");
                }
            } else {
                throw new RuntimeException("没有这个订单类型");
            }
            order.setStatus(status);
            order = erpOrderService.createErpOrder(order, erpOrderItems);
//            if (order.getOriginOrderSn().contains("CGDD")){
//                orderItemMapper.updateIsInTo(order.getOriginOrderSn(),1);
//            }else if (null!=order.getOriginOrderSn()&&!"".equals(order.getOriginOrderSn())){
//                orderItemMapper.updateIsOut(order.getOriginOrderSn(),1);
//            }
            return ResultUtil.success("创建成功!", order);
        } catch (RuntimeException e) {
            logger.warn(e.getMessage());
            return ResultUtil.error(e.getMessage());
        }
    }

    @PostMapping("/addin/{orderNo}")
    @ApiOperation("添加入库单")
    public Result addInOrder(@ApiParam("订单号") @PathVariable String orderNo,
                             @ApiParam("用户ID") @RequestParam("userId") Integer userId,
                             @ApiParam("订单商品") @RequestParam("items") String json) {
        return addOrderAndStatus(orderNo, userId, 0, json, MODE_IN, 0, "", "", "", new BigDecimal("0"));
    }

    @PostMapping("/addout/{orderNo}")
    @ApiOperation("添加出库单")
    public Result addOutOrder(@ApiParam("订单号") @PathVariable String orderNo,
                              @ApiParam("店家ID") @RequestParam("storeId") Integer storeId,
                              @ApiParam("原始订单号") @RequestParam("originOrder") String originOrder,
                              @ApiParam("客户ID") @RequestParam("userId") Integer userId,
                              @ApiParam("订单备注") @RequestParam("context") String context,
                              @ApiParam("订单商品") @RequestParam("items") String json, @RequestParam("logisticsCostRatio") BigDecimal logisticsCostRatio)

    {
        //出库提交之后默认财务审核
        return addOrderAndStatus(orderNo, userId, ErpOrderStatus.finance.getStatus(), json, MODE_OUT, storeId, originOrder, "", context,logisticsCostRatio);
    }


    @GetMapping("/inlist/{current}/{size}")
    @ApiOperation("入库订单列表查询")
    public Result listByIn(@ApiParam("查询页数") @PathVariable int current,
                           @ApiParam("查询数量") @PathVariable int size,
                           @ApiParam("查询订单号") @RequestParam("search") String search,
                           @ApiParam("起始时间") @RequestParam("start") String start,
                           @ApiParam("结束时间") @RequestParam("end") String end,
                           @ApiParam("查询用户姓名") @RequestParam("user") String user,
                           @ApiParam("查询对应名称") @RequestParam("name") String name,
                           @ApiParam("查询状态 -1 为查询全部") @RequestParam("status") int status,
                           @ApiParam("查询品牌名称") @RequestParam("brandName") String brandName) {

        String searchStr = searchStr(search, start, end, user, status, MODE_IN, name, brandName);
        IPage<ErpOrder> orders = erpOrderService.erpOrderList(searchStr, current, size);
        return ResultUtil.success("成功", orders);
    }

    @GetMapping("/outlist/{current}/{size}")
    @ApiOperation("出库订单列表查询")
    public Result listByOut(@ApiParam("查询页数") @PathVariable int current,
                            @ApiParam("查询数量") @PathVariable int size,
                            @ApiParam("查询订单号") @RequestParam("search") String search,
                            @ApiParam("起始时间") @RequestParam("start") String start,
                            @ApiParam("结束时间") @RequestParam("end") String end,
                            @ApiParam("查询对应名称") @RequestParam("name") String name,
                            @ApiParam("查询用户姓名") @RequestParam("user") String user,
                            @ApiParam("品牌名称") @RequestParam("brandName") String brandName,
                            @ApiParam("查询状态 -1 为查询全部") @RequestParam("status") int status) {
        String searchStr = searchStr(search, start, end, user, status, MODE_OUT, name, brandName);
        IPage<ErpOrder> orders = erpOrderService.erpOrderList(searchStr, current, size);
        return ResultUtil.success("成功", orders);
    }

    @GetMapping("/itemlist/{orderInfo}")
    @ApiOperation("获取订单的货品单")
    public Result listByItem(@ApiParam("订单号") @PathVariable String orderInfo) {
        try {
            List<ErpTempOrderItem> item = erpOrderService.getOrderItemByOrderNotDesc(orderInfo);
            return ResultUtil.success("成功!", item);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(e.getMessage());
        }
    }

    @GetMapping("/itemlist-desc/{orderInfo}")
    @ApiOperation("获取订单的货品单")
    public Result listByItemDesc(@ApiParam("订单号") @PathVariable String orderInfo) {
        try {

            List<ErpTempOrderItem> items = erpOrderService.getOrderItemByOrder(orderInfo);
            return ResultUtil.success("成功!", items);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(e.getMessage());
        }
    }

    @GetMapping("/itemlist-descs/{orderInfo}")
    @ApiOperation("获取订单的货品单")
    public Result listByItemDescs(@ApiParam("订单号") @PathVariable String orderInfo) {
        try {

            List<ErpTempOrderItem> items = erpOrderService.getOrderItemByOrders(orderInfo);
            return ResultUtil.success("成功!", items);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(e.getMessage());
        }
    }

    @DeleteMapping("/order/{id}")
    @ApiOperation("删除出入库订单")
    public Result deleteOrder(@ApiParam("订单ID") @Min(value = 1, message = "订单ID异常") @PathVariable Integer id) {
        if (erpOrderService.deleteOrder(id)) {
            return ResultUtil.success("删除成功!");
        }
        return ResultUtil.error("删除失败!");
    }


    /**
     * 拼接查询字符串
     *
     * @param search 查询条件
     * @param start  开始时间
     * @param end    结束时间
     * @param user   用户名
     * @param status 状态
     * @return
     */
    private String searchStr(String search, String start, String end, String user, int status, int mode, String name, String brandName) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(" WHERE ");

        buffer.append(" DATE_FORMAT(create_time, '%Y-%m-%d') >= ");
        buffer.append("'").append(start).append("'");
        buffer.append(" AND ");
        buffer.append(" DATE_FORMAT(create_time, '%Y-%m-%d') <= ");
        buffer.append("'").append(end).append("'");

        if (!Strings.isNullOrEmpty(search.trim())) {
            buffer.append(" AND");
            buffer.append(" order_info LIKE '%");
            buffer.append(search);
            buffer.append("%' ");
        }
        if (!Strings.isNullOrEmpty(user.trim())) {
            buffer.append(" AND");
            buffer.append(" operator LIKE '%");
            buffer.append(user);
            buffer.append("%' ");
        }
        if (!Strings.isNullOrEmpty(name.trim())) {
            buffer.append(" AND");
            if (mode == MODE_IN) {
                buffer.append(" supplier_name LIKE '%");
                buffer.append(name);
                buffer.append("%' ");
            } else {
                buffer.append(" search_name='");
                buffer.append(name);
                buffer.append("' ");
            }
        }
        if (!Strings.isNullOrEmpty(brandName.trim())) {
            buffer.append(" AND");
            buffer.append(" brand_name LIKE '%");
            buffer.append(brandName);
            buffer.append("%' ");
        }
        if (status == -1) {
            buffer.append(" AND mode = ").append(mode);
        } else {
            buffer.append(" AND");
            buffer.append(" status = ").append(status).append(" AND mode = ").append(mode);
        }

        //logger.info("条件语句: "+buffer.toString());
        return buffer.toString();
    }

    private AdminUser getUserById(int id) {
        AdminUser user = userMapper.selectById(id);
        Preconditions.checkNotNull(user, "未发现对应的用户");
        if (user.getStatus() != 0) {
            throw new RuntimeException("用户未被启用");
        }
        return user;
    }


    private List<ErpOrderItem> parseErpOrderItems(String json) {
        //  logger.info("JSON信息:" + json);
        JSONArray array = JSONArray.parseArray(json);
        List<ErpOrderItem> items = new ArrayList<>(array.size());
        JSONObject object;
        ErpOrderItem orderItem;
        for (int i = 0; i < array.size(); i++) {

            object = array.getJSONObject(i);
            orderItem = new ErpOrderItem();
            orderItem.setGoodsId(object.getInteger("goodsId"));
            orderItem.setGoodsList(object.getInteger("goodsList"));

            if (orderItem.getGoodsList() == 0) {
                orderItem.setGoodsList(4);
            }

            orderItem.setGoodsNum(object.getInteger("goodsNum"));
            orderItem.setGoodsPrice(object.getBigDecimal("goodsPrice"));

            Integer id = object.getInteger("id");
            if (id == null) {
                orderItem.setId(0);
            } else {
                orderItem.setId(object.getInteger("id"));
            }
            //orderItemId
            if (object.containsKey("orderItemId")) {
                orderItem.setOrderItemId(object.getInteger("orderItemId"));
            }
            if (object.containsKey("oweNum")) {
                orderItem.setOweNum(object.getInteger("oweNum"));
            }
            if (object.containsKey("isGive")) {
                orderItem.setIsGive(object.getInteger("isGive"));
            }
            if (object.containsKey("oweItem")) {
                orderItem.setOweItem(object.getInteger("oweItem"));
            }
            if (object.containsKey("discount")) {
                orderItem.setDiscount(object.getBigDecimal("discount"));
            } else {
                orderItem.setDiscount(BigDecimal.ONE);
            }
            items.add(orderItem);
        }
        return items;
    }

    /**
     * 库存汇总报表 列表 by ysh
     */
    @GetMapping("/sales-repertory/exportList")
    @ResponseBody
    @ApiOperation("按查询条件 库存汇总报表 列表")
    public Result repertoryexportList(@ApiParam("开始时间") @RequestParam("startTime") long start,
                                      @ApiParam("结束时间") @RequestParam("endTime") long end,
//	          @ApiParam("商品名称") @RequestParam("goods_name") String goods_name,
                                      @ApiParam("分类id") @RequestParam("cat_id") int cat_id,
                                      @ApiParam("供应商id") @RequestParam("supplier_id") int supplier_id,
                                      @ApiParam("商品名称") @RequestParam("goodsName") String goodsName) {
        // 分页
        try {
            List<RepertoryVOByYSH> result = erpOrderService.salesPageByYSHKC(start / 1000, end / 1000, cat_id, supplier_id, goodsName);
            return ResultUtil.success("成功", result);
        } catch (RuntimeException e) {
            return ResultUtil.error(e.getMessage());
        }

    }

    @GetMapping("/exportSearchName")
    @ResponseBody
    @ApiOperation("按出库供应商查询客户名称")
    public Result exportSearchName(@ApiParam("开始时间") @RequestParam("startTime") String start,
                                   @ApiParam("结束时间") @RequestParam("endTime") String end,
                                   @ApiParam("供应商id") @RequestParam("supplier_id") int supplier_id){
        return ResultUtil.success("成功", erpOrderMapper.exportSearchName(supplier_id,start.trim(),end.trim()));
    }

    @GetMapping("/i")
    public int i() {
        List<Supplier> suppliers = supplierMapper.selectList(new QueryWrapper<Supplier>());
        int rs = 0;
        for (Supplier supplier : suppliers) {
            List<String> orderSn = erpOrderMapper.getOrderSn(supplier.getSuppliersId());
            for (String s : orderSn) {
                rs += erpOrderMapper.update11(s, supplier.getLogisticsCostRatio());
            }
        }
        return rs;
    }

}
